package com.briup.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;

/**
 * 使用数据库连接池 获取数据库连接
 */
public class DruidGetConnection {
    public static Properties loadProperties() throws IOException {
        Properties properties = new Properties();
        properties.load(DruidGetConnection.class.getClassLoader().getResourceAsStream("druid.properties"));
        return properties;
    }

    public static void main(String[] args) {
        try {
            //获取连接池对象
            DataSource dataSource = DruidDataSourceFactory.createDataSource(loadProperties());
            //获取连接通过连接池对象
            Connection connection = dataSource.getConnection();
            System.out.println(connection);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
